<template>
  <a-select :options="list" :mode="multiple ? 'multiple' : undefined" />
</template>

<script setup lang="ts">
import { searchApi } from '@/api/search/search-api'
import { onMounted, shallowRef } from 'vue'

const props = defineProps({
  fetchParams: {
    type: Object,
    default: () => ({
      filter: {},
      op: {}
    })
  },
  // 新增：控制是否多选
  multiple: {
    type: Boolean,
    default: false
  },
  dropdownMatchSelectWidth: {
    type: Boolean,
    default: true
  }
})
// =========== 查询数据 =============
const list = shallowRef([])
async function queryList(fetchParams?: any) {
  try {
    const params = fetchParams ?? props.fetchParams
    const res = await searchApi.storeList(params)
    list.value = res.data.map((item) => {
      return {
        ...item,
        label: item.store_name,
        value: item.id
      }
    })
  } catch (error) {
    console.error(error)
  }
}

onMounted(queryList)

defineExpose({
  queryList
})
</script>
